package org.cx.comparator;

import lombok.RequiredArgsConstructor;

import java.lang.reflect.Proxy;


@RequiredArgsConstructor
@SuppressWarnings("unchecked")
public class ComparatorProxyFactory<T> {

    private final Class<T> comparator;
    private final ComparatorConfiguration configuration;

    public T newInstance() {
        final ComparatorProxy comparatorProxy = new ComparatorProxy(comparator, configuration);
        return (T) Proxy.newProxyInstance(comparator.getClassLoader(), new Class[]{comparator}, comparatorProxy);
    }
}
